import { HospitalPatientData } from '@/types/patient';
import {Patient} from "@/demo-data/types/patient";

export const hospitalPatientData: HospitalPatientData = {
  hospital_info: {
    name: "上海瑞金医院风湿免疫科",
    record_no: "SH20250408",
    doctor: "李主任"
  },
  patients: [
    {
      basic_info: {
        patient_id: "PT2025001",
        name: "黎天剑",
        gender: "男",
        age: 45,
        patient_no: "280339",
        telephone: "13603002228",
        idcard: "350212199308243058",
        first_flag: "是",
        clinical_type: "门诊",
        clinical_date: "2025-01-05"
      },
      examination: {
        ultrasound: [
          { result: "阳性" }
        ],
        CA72_4: {
          uml_value: "2.1"
        }
      },
      lab_results: {
        urid_acid: {
          ua: {
            value: 580,
            unit: "μmol/L"
          }
        },
        creatinine: {
          value: 110,
          unit: "μmol/L"
        }
      }
    },
    {
      basic_info: {
        patient_id: "PT2025002",
        name: "纪建源",
        gender: "男",
        age: 45,
        patient_no: "280343",
        telephone: "13603002228",
        idcard: "420106196912184973",
        first_flag: "是",
        clinical_type: "门诊",
        clinical_date: "2025-02-14"

      },
      examination: {
        ultrasound: [
          {
            result: "阳性"
          }
        ],
        CA72_4: {
          uml_value: "2.5"
        }
      },
      lab_results: {
        urid_acid: {
          ua: {
            value: 650,
            unit: "μmol/L"
          }
        },
        creatinine: {
          value: 104,
          unit: "μmol/L"
        }
      }
    },
    {
      basic_info: {
        patient_id: "PT2025003",
        name: "徐雄",
        gender: "男",
        age: 45,
        patient_no: "280343",
        telephone: "18956961719",
        idcard: "44068219810319131X",
        first_flag: "是",
        clinical_type: "住院",
        clinical_date: "2025-03-01"

      },
      examination: {
        ultrasound: [
          {
            result: "阳性"
          }
        ],
        CA72_4: {
          uml_value: "2.5"
        }
      },
      lab_results: {
        urid_acid: {
          ua: {
            value: 510,
            unit: "μmol/L"
          }
        },
        creatinine: {
          value: 98,
          unit: "μmol/L"
        }
      }
    },
    {
      basic_info: {
        patient_id: "PT2025004",
        name: "涛林",
        gender: "男",
        age: 45,
        patient_no: "280343",
        telephone: "15265412541",
        idcard: "370215192008158696",
        first_flag: "是",
        clinical_type: "门诊",
        clinical_date: "2025-01-12"

      },
      examination: {
        ultrasound: [
          {
            result: "阳性"
          }
        ],
        CA72_4: {
          uml_value: "2.3"
        }
      },
      lab_results: {
        urid_acid: {
          ua: {
            value: 580,
            unit: "μmol/L"
          }
        },
        creatinine: {
          value: 78,
          unit: "μmol/L"
        }
      }
    }
  ]
};

// 获取医院信息
export const getHospitalInfo = () => {
  return hospitalPatientData.hospital_info;
};

// 获取所有患者数据
export const getAllPatients = (): Patient[] => {
  return hospitalPatientData.patients;
};

// 根据患者ID获取数据
export const getPatientById = (id: string): Patient | undefined => {
  return hospitalPatientData.patients.find(
    patient => patient.basic_info.patient_id === id
  );
};

// 获取高尿酸患者(尿酸值>420 μmol/L)
export const getHighUricAcidPatients = (): Patient[] => {
  return hospitalPatientData.patients.filter(
    patient => patient.lab_results.urid_acid.ua.value > 420
  );
};

// 获取门诊患者
export const getOutpatients = (): Patient[] => {
  return hospitalPatientData.patients.filter(
    patient => patient.basic_info.clinical_type === "门诊"
  );
};

// 获取住院患者
export const getInpatients = (): Patient[] => {
  return hospitalPatientData.patients.filter(
    patient => patient.basic_info.clinical_type === "住院"
  );
};
